fio.pl

#!/usr/bin/perl
# Program name : my_fio_script_generator.pl
# Author : Mamadou Lamine Diatta
# Email: diatta at post dot harvard dot edu
# Purpose : Generate job files used by Linux command fio.
# ==========================================================================
# Here few example how to use fio at the command line without a job file.
#
#Storage subsystem:
# IBM EXP300 - 14 Disk Fiber Expansion, 17G - 15K RPMS
# Host: AMD Barcelona, 2 socket, 8G RAM
# HBA: QLogic Corp. ISP2312-based 2Gb Fibre Channel to PCI-X HBA (rev 02)
#
#Benchmark[1]:
# fio --name=guestrun --filename=/dev/mapper/volumes-fibre \
# --rw=randwrite --bs=16k --ioengine=libaio --direct=1 \
# --norandommap --runtime=120 --time_based --numjobs=1 \
# --group_reporting --thread --size=25g --write_lat_log \
# --write_bw_log --iodepth=74
#
#Qemu parameters:
# -m 1024 \
# -drive file=/images/npt2-guest-virtio.qcow2,if=ide,boot=on,snapshot=off \
# -drive file=/dev/mapper/volumes-fibre,if=virtio,cache=(on|off) \
# -drive file=/dev/mapper/volumes-npt2--dom1,if=virtio,cache=off
# -net nic,macaddr=00:FF:FF:00:00:01,model=rtl8139 -net tap -vnc :123 \
# -monitor stdio
#
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# Few functions here.
# ***************************************************************************
sub usage {
print<<END;

--------------------------------------------------------------------
Usage: $0 <directory>
Where: <directory> is a full path access read and write directory
NOTE: If the directory doesn't exist, it will be created if possible
i.e: $0 /asm01/fio/io1
--------------------------------------------------------------------

END
}
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sub generate_filename {
my $range = 36;
my $minimum = 0;
@ALPHA=('q','w','e','r','0','t','y','1','u','i','2','o','p','3','a','s','4','d','f','5','g','h','j','6','k','l','7','z','x','8','c','v','9','b','n','m');
$filenamesize=10;
$line=1;
$filename="";
while(1){
my $random_number = int(rand($range)) + $minimum;
$filename=$filename . $ALPHA[$random_number];
if ($line == $filenamesize) {
return $filename;
}
$line++;
}
}
# ***************************************************************************
sub generate_seconds {
my $range = 60;
my $minimum = 1;
my $seconds = int(rand($range)) + $minimum;
return $seconds;
}
# ***************************************************************************
sub generate_percent {
my $range = 100;
my $minimum = 1;
my $percent = int(rand($range)) + $minimum;
return $percent;
}
# ***************************************************************************
sub generate_numjobs {
my $range = 10;
my $minimum = 0;
my $numjobs = int(rand($range)) + $minimum;
return $numjobs;
}
# ***************************************************************************
sub generate_runtime {
my $range = 3600;
# Run between 1s or 1 hour = 60*60 seconds
my $minimum = 0;
my $runtime = int(rand($range)) + $minimum;
return $runtime;
}
# ***************************************************************************
sub generate_nrfiles {
my $range = 5000;
my $minimum = 1;
my $ioload = int(rand($range)) + $minimum;
return $ioload;
}
# ***************************************************************************
sub generate_filesize {
my $rangesize = 9;
my $rangebyte = 3;
my $minimum = 0;
@BYTE=('k','m','g');
@SIZEK=('1024','2048','4092','4096','5120','6144','7168','8192','9216');
@SIZEM=('100','200','300','400','500','600','700','800','900');
@SIZEG=('1','2','3','4','5','6','7','8','9');
$filesize="";

my $random_number = int(rand($rangebyte)) + $minimum;
my $byte=$BYTE[$random_number];
if ( $byte eq "k" ){
my $random_number = int(rand($rangesize)) + $minimum;
$filesize=$SIZEK[$random_number] . $byte;
}
elsif ( $byte eq "m" ){
my $random_number = int(rand($rangesize)) + $minimum;
$filesize=$SIZEM[$random_number] . $byte;
}
else {
my $random_number = int(rand($rangesize)) + $minimum;
$filesize=$SIZEG[$random_number] . $byte;
}
return $filesize;
}
# ***************************************************************************
sub generate_write_read_options {
my $rangerw = 4;
my $minimum = 0;
@RW=('read','randread','write','randwrite');
my $random_number = int(rand($rangerw)) + $minimum;
$rw=$RW[$random_number];
return $rw;
}
# ***************************************************************************
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# Main function
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#print "#ARGV=$#ARGV\n";
if ( $#ARGV != 0) {
&usage;
exit 1;
}
my $workingdir=$ARGV[0];
if ( ! -d "$workingdir" ) {
mkdir ($workingdir, 0755) ||
die "Can't make directory: $workingdir: $!\n";
}
else {
print "Directory: $workingdir already exist!\n";
}
while(1) {
$FIO="/usr/local/bin/fio";
$RM="/bin/rm -fr";
$CAT="/bin/cat";
my $scriptdir="/tmp";

my $fio_script= &generate_filename . ".fio";
open(F ,">$scriptdir/$fio_script") ||
die "Can't open file : $scriptdir/$fio_script : $!\n";

my $rw= &generate_write_read_options;
my $filename= &generate_filename;
my $filesize= &generate_filesize;
my $rwmixread= &generate_percent;
my $rwmixwrite= 100 - $rwmixread;
# Note: rwmixread and rwmixwrite are related and must
# add up to 100%.

my $nrfiles= &generate_nrfiles;
my $runtime= &generate_runtime;
my $numjobs= &generate_numjobs;
print F "; $rw $filesize with rwmixread=$rwmixread and rwmixwrite=$rwmixwrite\n";
print F "[${rw}-${rwmixread}-${rwmixwrite}]\n";
print F "rw=$rw\n";
print F "directory=$workingdir\n";
print F "filename=$filename\n";
print F "size=$filesize\n";
print F "rwmixread=$rwmixread\n";
print F "rwmixwrite=$rwmixwrite\n";
print F "nrfiles=$nrfiles\n";
print F "runtime=$runtime\n";
print F "description=${rw}_${filename}_${filesize}_${rwmixread}_${rwmixwrite}_${nrfiles}_${runtime}\n";
print F "unlink=1\n";
# If set unlink files when it's done.
print F "numjobs=$numjobs\n";
print F "write_bw_log\n";
# To write bandwidth log.
print F "write_lat_log\n";
# To write latency log.
print F "; ----------------------------------------------------\n\n\n";
close(F);
print "---------------------- Running $FIO $scriptdir/$fio_script\n";
open(R, "$scriptdir/$fio_script") ||
die "Can't open $scriptdir/$fio_script : $!\n";
while(<R>){
chop $_;
print "$_\n";
}
print "\n";
print "\n";
close(R);
`cat $scriptdir/$fio_script > ${fio_script}.log`;
`$FIO $scriptdir/$fio_script >> ${fio_script}.log 2>&1`;
`$RM $scriptdir/$fio_script`;
sleep 10;
}
# ***********************************************************************************
# #######################################################